package xcu.lxj.nettychat.chat.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import xcu.lxj.nettychat.chat.domain.vo.request.ContactFriendReq;
import xcu.lxj.nettychat.chat.domain.vo.response.ChatRoomResp;
import xcu.lxj.nettychat.chat.service.inter.ChatService;
import xcu.lxj.nettychat.chat.service.inter.RoomAppService;
import xcu.lxj.nettychat.common.domain.vo.request.CursorPageBaseReq;
import xcu.lxj.nettychat.common.domain.vo.request.IdReqVO;
import xcu.lxj.nettychat.common.domain.vo.response.ApiResult;
import xcu.lxj.nettychat.common.domain.vo.response.CursorPageBaseResp;
import xcu.lxj.nettychat.common.utils.RequestHolder;

/**
 * @Author XinJian Lei
 * @Date 2024/10/2 20:03
 * @Version 1.0
 */

@RestController
@Slf4j
@Tag(name="会话列表联系人相关接口")
public class ContactController {

    @Autowired
    private ChatService chatService;
    @Autowired
    private RoomAppService roomService;


    @PostMapping("/public/contact/page")
    @Operation(summary = "会话列表")
    public ApiResult<CursorPageBaseResp<ChatRoomResp>> getRoomPage(@RequestBody @Valid CursorPageBaseReq request) {
        Long uid = RequestHolder.get().getUid();
        log.info("{}",request);
        return ApiResult.success(roomService.getContactPage(request, uid));
    }


    @PostMapping("/public/contact/detail")
    @Operation(summary = "会话详情")
    public ApiResult<ChatRoomResp> getContactDetail(@RequestBody @Valid IdReqVO request) {
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(roomService.getContactDetail(uid, request.getId()));
    }

    @PostMapping("/public/contact/detail/friend")
    @Operation(summary = "会话详情(联系人列表发消息用)")
    public ApiResult<ChatRoomResp> getContactDetailByFriend(@RequestBody @Valid ContactFriendReq request) {
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(roomService.getContactDetailByFriend(uid, request.getUid()));
    }
}
